package com.t4l.client.screens.login.main;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.SplitLayoutPanel;
import com.google.gwt.user.client.ui.StackLayoutPanel;
import com.google.gwt.user.client.ui.Widget;
import com.t4l.client.images.Images;
import com.t4l.client.screens.login.main.chat.T4LChat;

public class MainScreen extends Composite {

	private SplitLayoutPanel layout;

	public MainScreen() {

		layout = new SplitLayoutPanel(5);
		layout.ensureDebugId("cwSplitLayoutPanel");

		layout.setWidth("100%");
		layout.setHeight(Window.getClientHeight() + "px");
		T4LChat t4lChat = new T4LChat();

		StackLayoutPanel stackPanel = new StackLayoutPanel(Unit.PX);
		stackPanel.setWidth("200");
		stackPanel.setHeight("100%");
		stackPanel.add(new HTML("Coming soon"),
				createHeaderWidget("Enlaces", Images.get().links()), 36);
		stackPanel.add(new HTML("Muy pronto"),
				createHeaderWidget("Notas", Images.get().notes()), 36);
		stackPanel.add(t4lChat,
				createHeaderWidget("Contactos", Images.get().contactAddress()),
				36);

		layout.addWest(stackPanel, 200);

		layout.add(new T4LMainSection());

		initWidget(layout);
		Window.addResizeHandler(new ResizeHandler() {
			@Override
			public void onResize(ResizeEvent event) {
				layout.setHeight(Window.getClientHeight() + "px");
			}
		});
	}

	/**
	 * Create a widget to display in the header that includes an image and some
	 * text.
	 * 
	 * @param text
	 *            the header text
	 * @param image
	 *            the {@link ImageResource} to add next to the header
	 * @return the header widget
	 */
	private Widget createHeaderWidget(String text, ImageResource image) {
		// Add the image and text to a horizontal panel
		HorizontalPanel hPanel = new HorizontalPanel();
		hPanel.setHeight("100%");
		hPanel.setSpacing(0);
		hPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		hPanel.add(new Image(image));
		HTML headerText = new HTML(text);
		hPanel.add(headerText);
		return new SimplePanel(hPanel);
	}

}
